<?php


session_start();
if (!isset($_SESSION['uid']))
{
header('Location:index.php?redirection=' . urlencode( $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] ) );
exit;
}
include('config.php');
draw_header('Check-in');
draw_menu($_SESSION['uid']);
@draw_status_bar('Documents Currently Checked Out To You', $_POST['last_message']); 

$query = "SELECT {$GLOBALS['CONFIG']['db_prefix']}data.id, 
				{$GLOBALS['CONFIG']['db_prefix']}user.last_name, 
				{$GLOBALS['CONFIG']['db_prefix']}user.first_name, 
				realname, 
				created, 
				description, 
				status 
				FROM {$GLOBALS['CONFIG']['db_prefix']}data, 
				{$GLOBALS['CONFIG']['db_prefix']}user 
				WHERE status = '{$_SESSION['uid']}' 
				AND {$GLOBALS['CONFIG']['db_prefix']}data.owner = {$GLOBALS['CONFIG']['db_prefix']}user.id";
				
$result = mysql_query($query, $GLOBALS['connection']) or die ("Error in query: $query. " . mysql_error());

$count = mysql_num_rows($result);
if ($count == 0)
	echo '<img src="images/exclamation.gif"> No documents checked out to you';
else
{
    echo '<table border="0" hspace="0" hgap="0" cellpadding="1" cellspacing="1"><caption><b>'.$count.' document';
	if ($count != 1)
		echo 's';
	echo ' checked out to you</caption>';
	echo '<tr bgcolor="#83a9f7">';
        echo '<td class="listtable"><b>Check-In</td>';
        echo '<td class="listtable"><b>File Name</td>';
        echo '<td class="listtable"><b>Description</td>';
        echo '<td class="listtable"><b>Created Date</td>';
        echo '<td class="listtable"><b>Owner</td>';
        echo '<td class="listtable"><b>Size</td>';
        echo '</tr>';

        $row_color = "#FCFCFC";
	while(list($id, $last_name, $first_name, $realname, $created, $description, $status) = mysql_fetch_row($result))
	{
	if ($description == '') 
        {
            $description = 'No information available'; 
        }
	$filename = $GLOBALS['CONFIG']['dataDir'] . $id . '.dat';
    $highlighted_color = '#bdf9b6';

    echo '<tr valign="middle" bgcolor="' . $row_color . '" onmouseover="this.style.backgroundColor=\'' . $highlighted_color . '\';" onmouseout="this.style.backgroundColor=\'' . $row_color . '\';">';
    echo '<td class="listtable"><a href="check-in.php?id=' . $id . '&amp;state=' . ($_REQUEST['state']+1) . '"><img src="images/check-in.png" border="0" width="45" height="45" alt="check in" /></a></td>';
    echo '<td class="listtable">' . $realname . '</td>';
    echo '<td class="listtable">' . $description . '</td>';
    echo '<td class="listtable">' . fix_date($created) . '</td> ';
    echo '<td class="listtable">' . $last_name . ', ' . $first_name . '</td> ';
    echo '<td class="listtable">' . display_filesize($filename) . '</td> ';
	echo '</tr>';

        if ( $row_color == "#FCFCFC" )
          $row_color = "#E3E7F9";
        else
          $row_color = "#FCFCFC";
	}

	mysql_free_result ($result);

	echo '</table>';
}

draw_footer();
?>
